#ifndef WORKSPACEWIDGET_H
#define WORKSPACEWIDGET_H

#include <QFrame>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QWheelEvent>
#include <QMouseEvent>

#include "../global/defines.h"
#include "rightpanel.h"

class RenderView;
class RenderScene;
class WorkspaceWidget : public QFrame
{
    Q_OBJECT
public:
    explicit WorkspaceWidget(QWidget *parent = nullptr);
    void initUI();
    void initConnections();

signals:

public slots:
    void setupMatrix();

private:
    QSharedPointer<RenderView> mRenderView;
    QSharedPointer<RenderScene> mScene;
    QSharedPointer<RightPanel> mRightPanel;

    int mMinZoomFactor;
    int mMaxZoomFactor;
    int mZoomFactor;
    int mZoomBase;
};

class RenderView: public QGraphicsView{
    Q_OBJECT
public:
    explicit RenderView(QWidget* parent = nullptr);
signals:
    void reqeustZoomIn();
    void requestZoomOut();

protected:
    void wheelEvent(QWheelEvent* event) override;
    void mouseMoveEvent(QMouseEvent* e) override;
    void mousePressEvent(QMouseEvent* e) override;
    void mouseReleaseEvent(QMouseEvent* e) override;
    void dragEnterEvent(QDragEnterEvent *event) override;

private:
    QPoint mPressedPos;
    bool mMousePressed;
};

class RenderScene: public QGraphicsScene{
    Q_OBJECT
public:
    explicit RenderScene(QObject* parent = nullptr);

protected:
    void dropEvent(QGraphicsSceneDragDropEvent *event) override;
    void dragEnterEvent(QGraphicsSceneDragDropEvent *event) override;
    void dragMoveEvent(QGraphicsSceneDragDropEvent *event) override;
    void dragLeaveEvent(QGraphicsSceneDragDropEvent *event) override;
    void keyPressEvent(QKeyEvent *event) override;
    QPoint mDropPos;
};

#endif // WORKSPACEWIDGET_H
